<?php
/*
by wolfy
*/

include("core.php");
include("config.php");


header("Content-type: text/html; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";

	echo "<head>";

	echo "<title>$stitle</title>";
	echo "<link rel=\"StyleSheet\" type=\"text/css\" href=\"style/style.css\" />";
	echo "</head>";

	echo "<body>"; 
connectdb();

        
        //clearnc();
$action=$_GET["action"];
$id=$_GET["id"];
$sid = $_GET["sid"];
if(islogged($sid)==false)
    {
        
      echo "<p align=\"center\">";
      echo "You are not logged in<br/>";
      echo "Or Your session has been expired<br/><br/>";
      echo "<a href=\"index.php\">Login</a>";
      echo "</p>";
      exit();
    }
    $uid = getuid_sid($sid);
    if(isbanned($uid))
    {
        
      echo "<p align=\"center\">";
      echo "<img src=\"images/notok.gif\" alt=\"x\"/><br/>";
      echo "You are <b>Banned</b><br/>";
      $banto = mysql_fetch_array(mysql_query("SELECT timeto FROM ibwf_penalties WHERE uid='".$uid."' AND penalty='1'"));
      $remain = $banto[0]- time();
      $rmsg = gettimemsg($remain);
      echo "Time to finish your penalty: $rmsg<br/><br/>";
      //echo "<a href=\"index.php\">Login</a>";
      echo "</p>";
      exit();
    }


                 //start of main card
////////////////////////////////////////MAIN PAGE
  addonline(getuid_sid($sid),"Joaca Trivia","");
echo "<p align=\"center\">";
echo "Testeaza-ti nivelul de cultura generala<br/>";
echo "Incearca sa raspunzi corect la cat mai multe intrebari<br/>";

if ($trivia_id == "")
{
$trivia_id = "1";
}

if ($answer)
	{
	$type = "1";
	$sql2 = mysql_query("SELECT trivia_id, question, answer, alternative1, alternative2 from trivia where trivia_id = $trivia_id");
	while($row = mysql_fetch_array($sql2)){
	$answer2 = ($row["answer"]);
	$alternative1 = ($row["alternative1"]);
	$alternative2 = ($row["alternative2"]);
	}

		if ($answer == $answer2) 
		{
		$correct = "1";
		}
		elseif ($answer == $alternative1) 
		{
		$correct = "1";
		}
		elseif ($answer == $alternative2) 
		{
		$correct = "1";
		}
		else
		{
		$wrong = "1";
		}
		
			if ($correct == "1")
			{
			$wrong = "0";
			}
			else
			{
			$correct = "0";
			}
		
	}




if( $type == "1" )
	{
			if ($correct == "1")
			{
			echo "<b>CORRECT</b><br/><br/>";
			}
		
			if ($wrong ==  "1")
			{
			echo "<b>WRONG</b><br/><br/> the correct answer was: ";
			$sql3 = mysql_query("SELECT trivia_id, question, answer, alternative1, alternative2 from trivia where trivia_id = $trivia_id");
			while($row = mysql_fetch_array($sql3)){
	 		echo ($row["answer"]);
			echo "<br/><br/>";
			}
			}

	}
	else
	{
	$sql = mysql_query("SELECT trivia_id, question, answer, alternative1, alternative2 from trivia where trivia_id = $trivia_id");
			while($row = mysql_fetch_array($sql)){
			echo ("<b>Question:</b><br/><br/>". $row['question'] ." ");
			}
	echo "<br><br><br><form name=\"trivia\" method=\"post\" action=\"$php_self\">";
	echo "<b>Answer:</b><br><br><input type=\"text\" name=\"answer\" class=\"userinputnm\"><br><input type=\"Submit\" name=\"Submit\" value=\"Submit\" class=\"submitbuttonnm\">";
	echo "</form>";
	}

if ($trivia_id == "1")
{
$trivia_id1 = "1";
$text = "";
}
else
{
$trivia_id1 = $trivia_id - "1";
$text = "Prev &#171;";
}

if ($trivia_id == "100")
{
$trivia_id2 = "2";
$text2 = "";
}
else
{
$trivia_id2 = $trivia_id + "1";
$text2 = "&#187; Next";
}

echo "<a href=\"trivia.php?trivia_id=$trivia_id1&amp;sid=$sid\">$text</a>";
echo "";
echo "<a href=\"trivia.php?trivia_id=$trivia_id2&amp;sid=$sid\">$text2</a>";
echo "<br/><br/><a href=\"index.php?action=main&amp;sid=$sid\">&#171;";
echo "Home</a>";

  echo "</p>";

	echo "</body>";
	echo "</html>";
?>